#include "charset.h"

QSize Charset::m_charSize(32,32);

Charset::Charset() : SpriteRef()
{

}

Charset::Charset(const QString& imagePath, const QSize& charSize)
    : SpriteRef(imagePath, QPoint(0,0), QRect(QPoint(0,0), charSize))
{
    setAction(STOP, DOWN);
}

void Charset::setImage(const QString& imagePath, const QSize& charSize)
{
    SpriteRef::setImage(imagePath);
    SpriteRef::setSubRect(QRect(QPoint(0,0), charSize));
    setAction(STOP, DOWN);
}

void Charset::setAction(CharAction action)
{
    m_subRect.moveTop((int)action * m_charSize.height());
    SpriteRef::setSubRect(m_subRect);
    m_action = action;
}

void Charset::setAction(CharAction action, CharDirection direction)
{
    setAction(action);
    setDirection(direction);
}

void Charset::setDirection(CharDirection direction)
{
    m_subRect.moveLeft((int)direction * m_charSize.width());
    SpriteRef::setSubRect(m_subRect);
    m_direction = direction;
}

CharAction Charset::getAction() const
{
    return m_action;
}

CharDirection Charset::getDirection() const
{
    return m_direction;
}

